const usersModel = require('../model/adminUsersModel.js');
module.exports = {
  adminDoLogin (req,res){
    // 获取浏览器发回来的数据
    // let {email,password} = req.body;

    // 验证邮箱，密码是否准确
usersModel.validateEmailAndPassword(req.body.email,req.body.password,(err,result)=>{
  if(err) console.error(err);
  let resObj = {};
  if(result){
resObj.code = 200;
resObj.msg = '登陆成功';
// 把数据存储在session里面  isLogin = true; 
req.session.isLogin = true;
// 登陆信息
req.session.userInfo = result;
  }else{
    resObj.code = 401,
    resObj.msg = '登陆失败'
  };
  res.send(resObj);
});
    // 返回结果
},
deleteUserById (req,res){
  usersModel.deleteUserById(req.query.id,(err,result)=>{
    if(err) console.error(err);
    let resObj = {
      code: 200,
      msg: '删除成功'
    };
    if(result.affectedRows == 1){
         res.send(resObj);
    }else{
         resObj.code = 401;
         msg = '删除失败';
         res.send(resObj);
    }
 });
},
getUserHeadAndNickName(req,res){
  // 从sessoin中把对应的用户头像和昵称获取出来
  let {nickname,avatar} = req.session.userInfo;
 if(req.session.userInfo){
   res.send({
     code: 200,
     msg: '获取成功',
     data: {
       nickname,avatar
     }
   });
 }else{
  res.send({
    code: 401,
    msg: '获取失败',
  });
 }
}
}